<?php //$Rev:: 55         $ // DO NOT REMOVE

function google_googleSearch(&$obj, $data)
{
    if ($text = $obj->core->module->aim_help_requested($data)) {
        $obj->core->utilities->aim_send_im($data['screenname'], $text, true);
    } else {
        //
        // Requires PHP 5.3.0 (anonymous function calls)
        //
        $googReq = function() use ($data) {
            $encoded = urlencode($data['message_text']);
            $request = 'http://www.google.com/search?q='.$encoded.'&btnI=I%27m+Feeling+Lucky';
            $header = get_headers($request, true);
            if (!empty($header['Location'])) {
                $location = (is_array($header['Location'])) ? $header['Location'][0] : $header['Location'];
                return ($header[0] == 'HTTP/1.0 302 Found') ? 'I found the following link for <b>'.$data['message_text'].'</b>: <a href="'.$location.'">' . $location . '</a>' : 'Sorry, no link found for "<b>' . $data['message_text'] . '</b>"';
            }
            return 'Sorry, no link found for "<b>' . $data['message_text'] . '</b>"';
        };
        
        if ($data['message_type'] == AIM_MSG_CHAT) {
            $obj->core->chat->aim_chat_send($data['cid'], $googReq());
        } else {
            $obj->core->utilities->aim_send_im($data['screenname'], $googReq(), true);
        }
    }
}

?>